<?php
/**
 * 订单处理函数库
*/

/**
 * 获取订单详情信息
 * @param   int     $order_id   订单id（如果order_id > 0 就按id查，否则按sn查）
 * @param   string  $order_sn   订单号
 * @return  array   订单信息（金额都有相应格式化的字段，前缀是formated_）
 */
function orderInfo($order_id, $order_sn = '') {
    /* 计算订单各种费用之和的语句 */
    $order_id = intval($order_id);
    if ($order_id > 0)
    {
        $sql = "SELECT * FROM " . T('order_info') .
                " WHERE order_id = '$order_id'";
    }
    else
    {
        $sql = "SELECT * FROM " . T('order_info') .
                " WHERE order_sn = '$order_sn'";
    }
    $order = D()->getRow($sql);
    /* 格式化字段 */
    if ($order)
    {
        $order['formated_goods_fee']    = priceFormat($order['goods_fee'], false);
        $order['formated_shipping_fee'] = priceFormat($order['shipping_fee'], false);
        $order['formated_pay_fee']      = priceFormat($order['pay_fee'], false);
        $order['formated_paid_fee']     = priceFormat($order['paid_fee'], false);
        $order['formated_total_fee']    = priceFormat($order['total_fee'], false);
        $order['formated_province']     = getRegionName($order['province']);
        $order['formated_city']         = getRegionName($order['city']);
        $order['formated_district']     = getRegionName($order['district']);
        $order['pay_name']              = getPayName($order['pay_id']);
        $order['shipping_name']         = getShippingName($order['shipping_id']);
        $order['status_name']           = getStatusName($order['status']);
    }
    return $order;
}